import config from '../../config/app'
import { emit as em } from '../services/socketio'

export const emit = em

export const find_list = (type, value, skip, sort, state, dispatch) => {
    sort = sort || { _id: -1 }

    let query = {}
    query[type] = { "$regex": value }
    emit({
        type: 'find',
        data: [
            config.list_db,
            { ...query },
            sort,
            (skip - 1) * config.limit,
            config.limit
        ]
    })
    // dispatch({ type: 'global/fetch', payload: { sosuo_tiaojian: query } })
}

// 分页查询
export const Pagination_onChange = (e, type, value) => {
    document.querySelector('.ant-table-body').scrollTop = 0
    emit({ type: 'find', data: [config.list_db, { ...query }] })

}

// 搜索查询
export const onSearch = (type, value) => {
    let query = {}
    query[type] = { "$regex": value }
    emit({ type: 'find', data: [config.list_db, { ...query }] })

}